/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fusiondata;

import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Administrator
 */
public class UseMySql extends  DataFromDB{
    
    private String dbName; //数据库名
    private String userName; //用户名
    private String password;//密码
    private String port;//连接的端口
    private String link;//连接地址
    private final static String DBDRIVER = "com.mysql.jdbc.Driver";

   
    /*
     * @param dbName 连接的数据库
     **/
    public UseMySql(String dbName, String userName, String password, String link) {
        this.dbName = dbName;
        this.userName = userName;
        this.password = password;
        this.link = link;
        this.port = "3306";
        initConnection();
    }

    public UseMySql(String dbName, String userName, String password, String port, String link) {
        this.dbName = dbName;
        this.userName = userName;
        this.password = password;
        this.port = port;
        this.link = link;
        initConnection();
    }

    private void initConnection(){
        String url = "jdbc:mysql:" + port + "//" + link + "/" + dbName;
        try
        {
            Class.forName(DBDRIVER);
            this.conn = DriverManager.getConnection(url,userName,password);
        }
        catch(ClassNotFoundException ce)
        {
            ce.printStackTrace();
        }
        catch(SQLException se)
        {
            se.printStackTrace();
        }
    }

    
}
